package com.yidu.InventoryManagement.controller;

import com.yidu.InventoryManagement.Util.IdUtil;
import com.yidu.InventoryManagement.entity.CashAccrualStock;
import com.yidu.InventoryManagement.service.cashAccrualStockService;
import com.yidu.InventoryManagement.service.securityAccrualStockService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author z
 * @version 1.0
 * @date 2022/12/8
 * 现金应收应付库存
 */
@RestController
public class cashAccrualStockController {
    @Resource
 private cashAccrualStockService cashAccrualStockService;
    /**
     * 分页查询
     * @param limit
     * @param page
     * @param date
     * @param businessType
     * @return
     */
    @RequestMapping("/selectCashAccrualStockInfo")
    public Map<String,Object> selectCashAccrualStockInfo(int limit, int page, String date,String businessType){
        return cashAccrualStockService.selectCashAccrualStock(limit,page,date,businessType);
    }


    //数据新增
    @RequestMapping("/addCashAccrualStock")
    public int addCashAccrualStock(CashAccrualStock accrualStock){
        System.out.println("进来了添加8888"+accrualStock);
        //查询最大的id
        String s = cashAccrualStockService.getmaxcashAccrualStockId();
        System.out.println(s+"////");
        int i1 = cashAccrualStockService.selectCashAccrualStockId();
        System.out.println(i1+"]]]]]");

        int i=0;
        if(i1==0){
            String id="6228480089371993680";
            accrualStock.setCashAccrualStockId(id);
            i = cashAccrualStockService.addCashAccrualStock(accrualStock);
        }else{
            String s1=cashAccrualStockService.getmaxcashAccrualStockId();
            System.out.println(s1+"SSSS");
            IdUtil idUtil=new IdUtil();
            String id = idUtil.createID(s1);
            accrualStock.setCashAccrualStockId(id);
            i=cashAccrualStockService.addCashAccrualStock(accrualStock);
        }
        return i;
    }


    //修改
    @RequestMapping("/updateCashAccrualStock")
    public int updateCashAccrualStock(CashAccrualStock accrualStock){
        System.out.println("修改"+accrualStock);
        int i=cashAccrualStockService.updateCashAccrualStock(accrualStock);
        if(i>0){
            System.out.println("修改成功"+i);
        }else{
            System.out.println("修改失败"+i);
        }
        return i;
    }
    //删除通过id删除
    @RequestMapping("/deleteCashAccrualStock")
    public int deleteCashAccrualStock(String cashAccrualStockId){
        System.out.println("进来了删除的方法"+cashAccrualStockId);
        int i = cashAccrualStockService.deleteCashAccrualStock(cashAccrualStockId);

        if(i>0){
            System.out.println("删除成功"+i);
        }else{
            System.out.println("删除失败"+i);
        }
        return i;
    }

    /**
     * 下拉表格的查询基金信息
     * @param page 当前页
     * @param limit 每页显示数
     * @param accountName 现金名称
     * @return list 集合
     */
    @RequestMapping("selectCashIdAndAccountName")
    public Map selectCashIdAndAccountName(int page, int limit, String accountName) {
        return cashAccrualStockService.selectCashIdAndAccountName(page,limit,accountName);
    }

}
